package dfs;

import common.DFileID;
import java.io.Serializable;
import common.Constants;

public class Inode implements Serializable {

	int[] blockArray;
	int size;
	DFileID fileID;
	boolean isFree;
	
	public Inode(){
		
	}
	
	public Inode(DFileID id){
		this.fileID =id;
		isFree = true;
		blockArray = new int[Constants.MAX_FILE_SIZE/Constants.BLOCK_SIZE];
	}
	
	
	public int[] getBlocks(){
		return blockArray;
	}
	
	public void addBlock(int blockNumber, int index){
		blockArray[index] = blockNumber;
	}
	
	public void setSize(int size){
		this.size = size;
	}
	
	public int getSize(){
		return size;
	}
	
	
	/**
	 * returns the DFileID of the file of this Inode
	 * @return
	 */
	public DFileID getID(){
		return fileID;
	}
	
	public boolean isFree(){
		return isFree;
	}
	
	public void toggleFree(){
		if (isFree) {
			isFree = false;
		}
		else isFree = true;
	}
	
	
}
